﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Core;

namespace MusicExplorer.Extensions
{
    public static class CoreDispatcherExtensions
    {
        public static async Task ExecuteInUIThread(this CoreDispatcher dispatcher, Func<Task> action)
        {
            var dispatcherTask = new TaskCompletionSource<object>();
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    await action();
                    dispatcherTask.SetResult(new object());
                });
            dispatcherTask.Task.Wait();
        }
    }
}
